package com.tjsinfo.tjsoa.documentationflow.dangweishouwen.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONArray;
import org.json.JSONObject;

import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.documentationflow.dangweishouwen.bo.ITDangweishouwenNeirongBO;
import com.tjsinfo.tjsoa.documentationflow.dangweishouwen.vo.TDangweishouwenNeirong;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.bo.ITXingzhengfawenNeirongBO;
import com.tjsinfo.tjsoa.workflow.WorkFlowTemplate;



/**
 * 党委收文管理查询发文
 * @author Administrator
 *
 */
public class AdminselectAction extends Action{
	private ITDangweishouwenNeirongBO dangweishouwenNeirongBO;
	
	public ITDangweishouwenNeirongBO getDangweishouwenNeirongBO() {
		return dangweishouwenNeirongBO;
	}
	public void setDangweishouwenNeirongBO(
			ITDangweishouwenNeirongBO dangweishouwenNeirongBO) {
		this.dangweishouwenNeirongBO = dangweishouwenNeirongBO;
	}


	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		String path = request.getContextPath();
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
		List<TDangweishouwenNeirong> list;
		JSONArray array = new JSONArray();
		JSONObject object = new JSONObject();
		if (request.getParameter("start") == null) {
			list =  dangweishouwenNeirongBO.selectDangweishouwenPage(0, 23,request.getParameter("laiwenjihuan"),request.getParameter("laiwenzihao"),request.getParameter("zhaiyao"));
		} else {
			Integer first = Integer.parseInt(request.getParameter("start"));
			list = dangweishouwenNeirongBO.selectDangweishouwenPage(first, 23,request.getParameter("laiwenjihuan"),request.getParameter("laiwenzihao"),request.getParameter("zhaiyao"));
		}
		Integer totalProperty = dangweishouwenNeirongBO.selectDangweishouwenTotalLine(request.getParameter("laiwenjihuan"),request.getParameter("laiwenzihao"),request.getParameter("zhaiyao"));
		object.put("totalProperty", totalProperty);
		for (TDangweishouwenNeirong dangweishouwenNeirong : list) {
			JSONObject shouwenJSON = new JSONObject();
			shouwenJSON.put("laiwenzihao", dangweishouwenNeirong.getLaiwenzihao());
			shouwenJSON.put("laiwenjihuan", dangweishouwenNeirong.getLaiwenjiguan());
			shouwenJSON.put("zongshouwenhao", dangweishouwenNeirong.getShouwenbianhao());
			shouwenJSON.put("zhaiyao", dangweishouwenNeirong.getZhaiyou());
			shouwenJSON.put("shouwenriqi", ToolKit.FormatDate(dangweishouwenNeirong.getLaiwenriqi()));
			if (workFlowTemplate.isEnd(Long.parseLong(dangweishouwenNeirong.getFlowid().toString()) )){
				shouwenJSON.put("state", "是");
				shouwenJSON.put("laiwenjihuan", dangweishouwenNeirong.getLaiwenjiguan());
				shouwenJSON.put("operate", "<a href='"+basePath+"documentationflow/dangweishouwen/genzong.jsp?flowid="+dangweishouwenNeirong.getFlowid()+
						"'>跟踪</a>&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/dangweishouwen/shenpi.do?method=selectonedoc&id="+dangweishouwenNeirong.getId()+"'>查看</a>&nbsp;&nbsp;"
						+"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/dangweishouwen/shenpi.do?method=guidangform&id="+dangweishouwenNeirong.getId()+"'>归档</a>");
			}
			else if (workFlowTemplate.isSuspend(Long.parseLong(dangweishouwenNeirong.getFlowid().toString()) )){
				shouwenJSON.put("state", "中止");
				shouwenJSON.put("laiwenjihuan", dangweishouwenNeirong.getLaiwenjiguan());
				if("登记修改".equals(workFlowTemplate.selectNodeName(Long.valueOf(dangweishouwenNeirong.getFlowid().toString())))){
					shouwenJSON.put("operate", "<a href='"+basePath+"documentationflow/dangweishouwen/genzong.jsp?flowid="+dangweishouwenNeirong.getFlowid()+
							"'>跟踪</a>&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/dangweishouwen/shenpi.do?method=selectonedoc&id="+dangweishouwenNeirong.getId()+"'>查看</a>&nbsp;&nbsp;"+"<a href='javascript:resume("+dangweishouwenNeirong.getFlowid()+")'>重启</a>"+
							"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/dangweishouwen/shenpi.do?method=xiugai&id="+dangweishouwenNeirong.getId()+"'>修改</a>&nbsp;&nbsp;"+"<a href='javascript:end(\""+dangweishouwenNeirong.getId()+"\")'>删除流程</a>&nbsp;&nbsp;");
				}else{
					shouwenJSON.put("operate", "<a href='"+basePath+"documentationflow/dangweishouwen/genzong.jsp?flowid="+dangweishouwenNeirong.getFlowid()+
							"'>跟踪</a>&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/dangweishouwen/shenpi.do?method=selectonedoc&id="+dangweishouwenNeirong.getId()+"'>查看</a>&nbsp;&nbsp;"+"<a href='javascript:resume("+dangweishouwenNeirong.getFlowid()+")'>重启</a>"+
							"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/dangweishouwen/shenpi.do?method=xiugai&id="+dangweishouwenNeirong.getId()+"'>修改</a>&nbsp;&nbsp;");
				}
				
			}
			else{
				shouwenJSON.put("state", "否");
				shouwenJSON.put("laiwenjihuan", dangweishouwenNeirong.getLaiwenjiguan());
				if("登记修改".equals(workFlowTemplate.selectNodeName(Long.valueOf(dangweishouwenNeirong.getFlowid().toString())))){
					shouwenJSON.put("operate", "<a href='"+basePath+"documentationflow/dangweishouwen/genzong.jsp?flowid="+dangweishouwenNeirong.getFlowid()+
							"'>跟踪</a>&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/dangweishouwen/shenpi.do?method=selectonedoc&id="+dangweishouwenNeirong.getId()+"'>查看</a>&nbsp;&nbsp;"+"<a href='javascript:suspend("+dangweishouwenNeirong.getFlowid()+")'>中止</a>"+
							"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/dangweishouwen/shenpi.do?method=xiugai&id="+dangweishouwenNeirong.getId()+"'>修改</a>&nbsp;&nbsp;"+"<a href='javascript:deleteprocess(\""+dangweishouwenNeirong.getId()+"\")'>删除流程</a>&nbsp;&nbsp;"+"<a href='javascript:end(\""+dangweishouwenNeirong.getFlowid()+"\")'>完结</a>");
				}else{
					shouwenJSON.put("operate", "<a href='"+basePath+"documentationflow/dangweishouwen/genzong.jsp?flowid="+dangweishouwenNeirong.getFlowid()+
							"'>跟踪</a>&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/dangweishouwen/shenpi.do?method=selectonedoc&id="+dangweishouwenNeirong.getId()+"'>查看</a>&nbsp;&nbsp;"+"<a href='javascript:suspend("+dangweishouwenNeirong.getFlowid()+")'>中止</a>"+
							"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/dangweishouwen/shenpi.do?method=xiugai&id="+dangweishouwenNeirong.getId()+"'>修改</a>&nbsp;&nbsp;"+"<a href='javascript:end(\""+dangweishouwenNeirong.getFlowid()+"\")'>完结</a>");
				}
				
			}
			if(dangweishouwenNeirong.getIsguidang() != null){
				shouwenJSON.put("state", "归档");
			}
			array.put(shouwenJSON);
		}
		request.getSession().setAttribute("dangweishouadminliststart", Integer.parseInt(request.getParameter("start")));
		object.put("root", array);
		response.getWriter().print(object);
		return null;
	}
	
}
